<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>angularJs</title>
    <meta name="Copyright" content="All Rights Reserved"/>
    <link rel="shortcut icon" type="image/x-icon" href="itcast.ico"/>
    <link rel="stylesheet" type="text/css" href="base.css"/>
    <script src="js/angular.min.js"></script>
    <script type="text/javascript">
        //定义一个模块
        var myApp = angular.module('myApp',[]);

        //给模块添加一个控制器
        myApp.controller('myController',function ($scope,$http) {
            //定义一个异步请求的方法
            $scope.sendPost = function () {
                $http.post("/user",{"name":"张三"}).then(function (response) {
                    //请求成功,将返回结果map集合存入scope域中(键值为res)
                    $scope.res = response.data;
                },function (reason) {
                    //请求失败
                    alert("请求失败");
                });
            };
        });
    </script>
</head>
<!-- 指定AngularJS应用的根元素 -->
<body ng-app="myApp" ng-controller="myController" ng-init="sendPost()">
{{res.msg}}
</body>
</html>